#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> findBall(vector<vector<int>>& grid) {
    vector<int> res;
    int m = grid.size(), n = grid[0].size();

    auto get = [&](int u)->int {
        int i = 0, j = u;
        while (i < m)
        {
            if (grid[i][j] == 1)
            {
                if (j + 1 == n || grid[i][j + 1] == -1)  return -1;
                i++, j++;
            }
            else
            {
                if (j - 1 < 0 || grid[i][j - 1] == 1)   return -1;
                i++, j--;
            }
        }
        return j;
    };

    for (int i = 0; i < n; i++)
    {
        res.push_back(get(i));
    }
    return res;
}